#include <stdint.h>
#include <button_bsp.h>
#include <main.h>
#include <stdio.h>
uint32_t press_down_time = 0;
uint32_t press_up_time = 0;
uint8_t press_state = 0;
uint8_t press_hold = 0;
uint32_t press_hold_time = 0;
void getKeyPressDown(void)
{
	press_down_time = systick_get_ms();
	press_state = 1;
}

void getKeyPressUp(void)
{
	press_up_time = systick_get_ms();
	press_state = 0;
}

uint8_t buttonClick(uint16_t count)
{
	uint8_t ret = 0;
	if (press_state == 1 && press_up_time - press_down_time > count * 10)
	{
		ret = 1;
		press_up_time = 0;
		press_down_time = 0;
	}
	
	return ret;
}

uint8_t buttonPress(uint16_t count1, uint16_t count2)
{
	uint8_t ret = 0;
	if (press_state == 1 && press_hold == 0)
	{
		press_hold = 1;
		press_hold_time = press_down_time;
	}
	else if (press_state == 0 && press_hold == 1)
	{
		press_hold = 0;
		press_hold_time = press_down_time;
	}
	if (press_down_time - press_hold_time > count2 * 10)
	{
		ret = 2;
	}
	else if (press_down_time - press_hold_time > count1 * 10)
	{
		ret = 1;
	}
	return ret;
}